package com.wdz.controller;

import com.wdz.entity.UserModel;
import com.wdz.service.HelloService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author ：Wu Dazhong
 * @Date :2019/6/10
 * @Description:请求控制器
 */
@Controller
public class HelloController {

     @Autowired
     private HelloService helloService;

    @ResponseBody
    @RequestMapping(value= "/hello",method = RequestMethod.GET)
    @ApiOperation("测试HelloWorld工程")
    public String Hello(){
        String s = helloService.find();
        return "你好，世界"+ s;
    }
    @ResponseBody
    @RequestMapping(value = "/addUser1", method = RequestMethod.GET)
    public String addUser1(String username,String password) {
        System.out.println("username is:"+username);
        System.out.println("password is:"+password);
        return "返回成功";
    }
    @ResponseBody
    @RequestMapping("/addUser2")
    public String addUser2(HttpServletRequest request) {
        String username=request.getParameter("username");
        String password=request.getParameter("password");
        System.out.println("username is:"+username);
        System.out.println("password is:"+password);
        return "吴大忠";
    }

    @ResponseBody
    @RequestMapping("/addUser3")
    public UserModel addUser3(@RequestBody UserModel user) {
        System.out.println("username is:"+user.getUsername());
        System.out.println("password is:"+user.getPassword());
        return user;
    }

    @ResponseBody
    @RequestMapping(value="/addUser4/{username}/{password}",method=RequestMethod.GET)
    public String addUser4(@PathVariable String username, @PathVariable String password) {
        System.out.println("username is:"+username);
        System.out.println("password is:"+password);
        return "方法四";
    }

    @ResponseBody
    @RequestMapping(value="/addUser6",method=RequestMethod.GET)
    public String addUser6(@RequestParam(value = "username",required = false) String username, @RequestParam("password") String password) {
        System.out.println("username is:"+username);
        System.out.println("password is:"+password);
        return "方法六";
    }
}
